package sumoTween.demo.swing.easings;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;

import sumoTween.Tweener;
import sumoTween.easing.Back;
import sumoTween.easing.Bounce;
import sumoTween.easing.Circ;
import sumoTween.easing.Cubic;
import sumoTween.easing.Expo;
import sumoTween.easing.Linear;
import sumoTween.easing.Quad;
import sumoTween.easing.Quart;
import sumoTween.easing.Quint;
import sumoTween.easing.Sine;

public class DemoComponent extends JComponent 
{

	Tweener testTween[]=new Tweener[3*numTweeners];

	static final int numTweeners=10;
	
	public DemoComponent()
	{
		// init all different tweeners...
    	for(int eas=0;eas<3;eas++)
    	{

	    	for(int ti=0;ti<numTweeners;ti++)
	    	{
	    		testTween[ti+eas*numTweeners]=new Tweener();
				if(ti==0)testTween[ti+eas*numTweeners].setEasing(new Linear());
				if(ti==1)testTween[ti+eas*numTweeners].setEasing(new Sine());
				if(ti==2)testTween[ti+eas*numTweeners].setEasing(new Quad());
				if(ti==3)testTween[ti+eas*numTweeners].setEasing(new Cubic());
				if(ti==4)testTween[ti+eas*numTweeners].setEasing(new Expo());
				if(ti==5)testTween[ti+eas*numTweeners].setEasing(new Back());
				if(ti==6)testTween[ti+eas*numTweeners].setEasing(new Bounce());
				if(ti==7)testTween[ti+eas*numTweeners].setEasing(new Quart());
				if(ti==8)testTween[ti+eas*numTweeners].setEasing(new Quint());
				if(ti==9)testTween[ti+eas*numTweeners].setEasing(new Circ());

				testTween[ti+eas*numTweeners].set(0f, 0f, eas);
				testTween[ti+eas*numTweeners].set(1f, 1f, eas);
	    	}
    	}
	}
	
	public void paint(Graphics g)
	{
		Font font=new Font("Arial", Font.PLAIN,10);
		g.setFont(font);
		g.setColor(new Color(0xffffff));
		g.fillRect(0, 0, getWidth(), getHeight());

		int posx=10;
		int posy=30;

		int countCells=0;
		int countRows=0;

    	for(int ti=0;ti<numTweeners*3;ti++)
    	{
    		if(countCells>=numTweeners)
    		{
    			countRows++;
    			countCells=0;
    			posy+=180;
    			posx=10;
    		}

    		Graphics2D g2d=(Graphics2D)g;
    	    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    	    g.setColor(new Color(0x999999));
    		
    		g.drawLine(posx-10, 20, posx-10,500);
    		
    		g.setColor(new Color(0xeeeeee));

    		g.fillRect(posx, posy, 100, 100);
    		g.setColor(new Color(0x555555));

    		int lastx=-1;
    		int lasty=-1;
    		float size=100f;
    		
    		for(float f=0.0f;f<=1f;f+=0.02f)
        	{
    			if(testTween[ti]!=null)
    			{
	        		float v =testTween[ti].getValue(f);

	        		if(lastx>=0)
	        			g.drawLine(
	        				posx+(int)(f*size), 
	        				posy+(int)(v*size), lastx,lasty);
	
	        		lastx=(int)(f*size)+posx;
	        		lasty=(int)(v*size)+posy;
    			}
    			else
    				System.out.println("null "+ti);
        	}

    		String easingString=" easing in";
    		if(countRows==1)easingString=" easing out";
    		else
    		if(countRows==2)easingString=" easing in+out";

    		if(testTween[ti]!=null)
    			g.drawString(
        			testTween[ti].getEasing().getClass().getSimpleName().toString()+easingString, 
        			posx+5, 
        			posy-10);

    		posx+=110+10;

    		countCells++;
    	}
	}
}






